import {
	request
} from '@/api/request/index.js'
import share from '@/components/share.vue'

export default{
	data(){
		return{
			classifyName:'',
			contentId:'',
			subjectList:[],
			commodityList:[],
			packageList:[],
			shareConfig:{
				Title:'嗨焙鲜生',
				Contents:'嗨焙鲜生',
				ShareLink:this.$currentlocation.getCurrentPageUrlWithArgs(),
				ImgsrcMp:''
			}
		}
	},
	onLoad:function(options){
		let contentId = options.contentid || ''
		let classifyName = options.classifyname || ''
		if(!classifyName) return uni.showToast({
			title:'缺少分类名称',
			icon:'none'
		})
		
		this.classifyName=classifyName
		this.contentId=contentId
		
		if(!contentId) this.getList()
		else this.getItem()
		// #ifdef H5
		this.initShare()
		// #endif
	},
	//微信小程序分享
	onShareAppMessage: function(res) {
		if (res.from === 'button') {}
		return {
			title: this.shareConfig.Title,
			path: this.$currentlocation.getCurrentPageUrlWithArgs(),
			imageUrl: this.shareConfig.ImgsrcMp,
			success(res){
			}
		};
	},
	methods:{
		getList(){
			let that =this;
			uni.showLoading({
				mask: true,
				title: '正在加载模块...'
			});
			request.get({
					data: {
						c: 'SubjectController',
						m: 'SubjectList',
						classifyName: that.classifyName
					}
				})
				.then(res => {
					console.log(res)
					if (res.Status == "ok") {
						let result = res.Tag?res.Tag.contents : []
						that.subjectList = result
					} else {
						return uni.showToast({
							title:res.Msg,
							icon:'none'
						})
					}
				})
				.catch(error => {
					console.error(error)
					
				});
		},
		getItem(){
			let that =this;
			uni.showLoading({
				mask: true,
				title: '获取订单信息...'
			});
			request.get({
					data: {
						c: 'SubjectController',
						m: 'SubjectList',
						classifyName: that.classifyName,
						contentId:that.contentId
					}
				})
				.then(res => {
					console.log(res)
					if (res.Status == "ok") {
						let result = res.Tag?res.Tag.contents : []
						that.subjectList = result
					} else {
						return uni.showToast({
							title:res.Msg,
							icon:'none'
						})
					}
				})
				.catch(error => {
					console.error(error)
					
				});
		},
		navigatorTo(href){
			uni.navigateTo({
				url: href
			})
		},
		initShare() {
			let that =this
			this.$ShareSdk.Share({
				title: that.shareConfig.Title,
				link: that.$currentlocation.getCurrentPageUrlWithArgs(),
				imgUrl:that.$resBaseurl+'/m-images/share/index.jpg',
				success() {
					
				}
			})
		},
	}
}